<?php

class CryoBB_Tag_Parameter extends CryoBB_Tag
{

	// Opening tag if parameter is present
    protected $openTagParameter;
    
    // Placeholder to replace with parameter
	protected $placeholder;
	
	/**
	 * Set the opening tag to use if a parameter is present
	 * 
	 * @param string $openTag Opening tag
	 * @param string $placeholder Placeholder to replace with parameter
	 */
	public function setOpenTagParameter($openTag, $placeholder = '')
	{
		$this->openTagParameter = $openTag;
		$this->placeholder = $placeholder;
	}
	
	/**
	 * Assembles the replacement for CryoBB_Base.  Not meant to be used.
	 * 
	 * @param string $content Text inside of tag
	 * @param string $parameter Parameter on tag (if any)
	 */
	public function build($parameter)
	{
		if (!empty($this->openTagParameter) && (empty($this->openTag) || !empty($parameter))) {
			$openTagParameter = str_replace($this->placeholder, $parameter, $this->openTagParameter);
			return array($openTagParameter, $this->closeTag);
		} else {
			return parent::build($parameter);
		}
	}	
}